home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-21 | 829 b | 48 lines | [TEXT/RLAB] |
- IF:
-
- The if statement is very similar to the C if statement.
-
- if ( expression )
- {
- statement(s)
- else
- statement(s)
- }
-
- The "else" is optional, and the braces are always required.
- The differences between the C-language if-statement and RLaB's
- are due to the special demands of an interactive language.
-
- Examples:
-
- if ( init )
- {
- mass = 10.0;
- inertia = 3*mass/length^3;
- init = 0;
- }
-
- if(class(data) == "string")
- {
- fprintf(file, data);
- else
- write(file, data);
- }
-
- if( class(v) != "matrix" ) { error(); }
-
- At present there is no explicit elseif statement. However the
- else if behavior can be implemented as it is in C (although
- RLaB's syntax is somewhat clumsy). For example:
-
- if( test1 )
- {
- x = a;
- else if( test2 ) {
- x = b;
- else if( test3 ) {
- x = c;
- else
- error();
- }}}
-